//
//  NRWHomeVC.m
//  Finance
//
//  Created by 邢毅 on 2018/7/31.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWHomeVC.h"

#import "NRWHomeCollectionCell.h"
#import "NRWFinancialCenterVC.h"
#import "NRWMissionCenterVC.h"

@interface NRWHomeVC ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) NSArray<NSString *> *homeImageArray;

@end

@implementation NRWHomeVC
{
	UICollectionView *_collectionView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.navigationView.title = @"首页";
	
	[self setupUI];
}

- (void)setupUI {
	
	UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
	layout.minimumLineSpacing = 0;
	layout.minimumInteritemSpacing = 0;
	layout.itemSize = CGSizeMake((SCREEN_WIDTH() - 32 - 13) / 2, 100);
	
	_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, getNavHeight(), SCREEN_WIDTH(), SCREEN_HEIGHT() - getNavHeight()) collectionViewLayout:layout];
	_collectionView.backgroundColor = [UIColor whiteColor];
	_collectionView.delegate = self;
	_collectionView.dataSource = self;
	_collectionView.contentInset = UIEdgeInsetsMake(15, 16, 0, 16);
	[_collectionView registerClass:NRWHomeCollectionCell.class forCellWithReuseIdentifier:@"cell"];
	[self.view addSubview:_collectionView];
}

#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
	
	return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
	
	return self.homeImageArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
	
	NRWHomeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
	
	cell.imageName = self.homeImageArray[indexPath.item];
	
	return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
	
	UIViewController *vc = nil;
	
	if (indexPath.item == 0) {
		vc = [[NRWFinancialCenterVC alloc] init];
	} else if (indexPath.item == 1) {
		vc = [[NRWMissionCenterVC alloc] init];
	}
	
	[self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - getter
- (NSArray<NSString *> *)homeImageArray {
	
	if (_homeImageArray == nil) {
		_homeImageArray = @[@"home_financialcenter", @"home_missioncenter"];
	}
	return _homeImageArray;
}

@end
